<template>
	<view>
		<view class="cenbox">
			<scroll-view scroll-y :style="{ height: windowHeight }" @scrolltolower="onreachBottom">
				<view class="itembox" @click="todetails(item)" v-for="(item,index) in infodetails" :key="index">
					<view class="topbox">
						<image :src="item.avatar" style="width: 72rpx;height: 72rpx;border-radius: 50%;" mode="">
						</image>
						<view class="r-box">
							<view class="" style="width: 80%;height: 100%;">
								<view class="nametxt">
									<view class="">
										{{item.nickname}}
									</view>
									<view class="" style="display: flex;align-items: center;margin-left: 20rpx;">
										<image src="/static/index/yc.png" style="width: 24rpx;height: 20rpx;" mode="">
										</image>
										<view class="">
											{{item.status == 'normal'?'未隐藏':'已隐藏'}}
										</view>
									</view>
								</view>
								<view class="timetxt">
									{{item.time}}发布
								</view>
							</view>
							<view class="" style="width: 40rpx;height: 40rpx;">
								<image src="/static/login/downicon.png" @click.stop="topop(item)"
									style="width: 40rpx;height: 40rpx;" mode=""></image>
							</view>
						</view>
					</view>

					<view class="centerbox">
						<view class="dongtaitxt">
							{{item.content}}
						</view>
						<view class="imgbox">
							<image :src="i" v-for="(i,k) in item.images" :key="k"
								style="width: 220rpx;height: 220rpx;border-radius: 16rpx;margin-bottom: 16rpx;margin-right: 10rpx;"
								mode=""></image>
						</view>

					</view>

					<view class="fpzbox">
						<view class="fenxiang">
							<image src="/static/index/fenxiang.png" style="width: 26rpx;height: 26rpx;" mode=""></image>
							<view class="nums">
								{{item.give}}
							</view>
						</view>
						<view class="pinglun">
							<image src="/static/index/pinglun.png" style="width: 26rpx;height: 26rpx;" mode=""></image>
							<view class="nums">
								{{item.comment}}
							</view>
						</view>
						<view class="zan">
							<image src="/static/index/dianzan.png" style="width: 26rpx;height: 26rpx;" mode=""></image>
							<view class="nums">
								{{item.collection}}
							</view>
						</view>
					</view>
				</view>
			</scroll-view>

		</view>
		<uni-popup ref="popup" type="bottom" border-radius="10px 10px 0 0">
			<view class="popbox">
				<view class="zhiding" @click="toshenqing">
					申请置顶
				</view>
				<view class="yinc" @click="toyinc">
					隐藏
				</view>
				<view class="sanc" @click="todel">
					删除
				</view>
				<view class="quxiao" @click="tocancel">
					取消
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import ikz from '@/pages/Common/tools.js';
	export default {
		data( ) {
			return {
				windowHeight: 0,
				code: 0,
				adminImgPath: getApp( ).globalData.adminImgPath,
				page: 1,
				limit: 10,
				infodetails: '',
				detailid: ''
			};
		},
		onLoad( ) {
			var _this = this
			uni.getSystemInfo( {
				success: function( res ) {
					_this.windowHeight = res.windowHeight - 13 + 'px';
					console.log( _this.windowHeight, '屏幕高度' );
				}
			} )
		},
		onShow( ) {
			this.init( )
		},
		methods: {
			topop( item ) {
				console.log( item, 'item' );
				this.detailid = item.id
				this.$refs.popup.open( 'bottom' )
			},
			// 申请置顶
			toshenqing( ) {
				console.log( '置顶接口' );
				var path = '/xyb/posts/posts/pinned';
				var data = {
					id: this.detailid,
					token: uni.getStorageSync( 'local_user_session' ),
					agent_id: uni.getStorageSync( 'default_agent' ).id
				};
				ikz.request( path, data, res => {
					console.log( res, 'rrrr' );
					if ( res.data.code == 1 ) {
						// this.list = res.data.data.data
						// this.infodetails = res.data.data.data
						uni.showToast( {
							title: res.data.msg,
							icon: 'none'
						} )
						this.init( )
					} else {
						uni.showModal( {
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function( res ) {}
						} );
					}
				} )



				this.$refs.popup.close( )
			},
			// 隐藏
			toyinc( ) {
				this.code = 1
				console.log( '隐藏' );
				var path = '/xyb/posts/posts/save_status';
				var data = {
					id: this.detailid,
					token: uni.getStorageSync( 'local_user_session' ),
					agent_id: uni.getStorageSync( 'default_agent' ).id
				};
				ikz.request( path, data, res => {
					console.log( res, 'rrrr' );
					if ( res.data.code == 1 ) {
						// this.list = res.data.data.data
						// this.infodetails = res.data.data.data
						uni.showToast( {
							title: res.data.msg,
							icon: 'none'
						} )
						this.init( )
					} else {
						uni.showModal( {
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function( res ) {}
						} );
					}
				} )


				this.$refs.popup.close( )
			},
			// 删除
			todel( ) {
				this.$refs.popup.close( )
				var _this = this
				uni.showModal( {
					title: '提示',
					content: '确定要删除该动态？',
					cancelColor: '#666666',
					confirmColor: '#FF3500',
					success: function( res ) {
						if ( res.confirm ) {
							console.log( '用户点击确定删除' );
							_this.del( )
						} else if ( res.cancel ) {
							console.log( '用户点击取消' );
						}
					}
				} );
			},

			del( ) {
				var path = '/xyb/posts/posts/del';
				var data = {
					id: this.detailid,
					token: uni.getStorageSync( 'local_user_session' ),
					agent_id: uni.getStorageSync( 'default_agent' ).id
				};
				ikz.request( path, data, res => {
					console.log( res, 'rrrr' );
					if ( res.data.code == 1 ) {
					
						this.init( )
					} else {
						uni.showModal( {
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function( res ) {}
						} );
					}
				} )
			},
			tocancel( ) {
				this.$refs.popup.close( )
			},
			init( ) {
				var path = '/xyb/posts/posts/user_posts';
				var data = {
					page: this.page,
					limit: this.limit,
					token: uni.getStorageSync( 'local_user_session' ),
					agent_id: uni.getStorageSync( 'default_agent' ).id
				};
				ikz.request( path, data, res => {
					console.log( res, 'rrrr' );
					if ( res.data.code == 1 ) {
						// this.list = res.data.data.data
						this.infodetails = res.data.data.data
					} else {
						uni.showModal( {
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function( res ) {}
						} );
					}
				} )
			},
			todetails( item ) {
				uni.navigateTo( {
					url: '/pages/Home/dongtaidetails/dongtaidetails?id=' + item.id
				} )
			},
		},
	}
</script>

<style lang="scss" scoped>
	.cenbox {
		width: 100%;
		min-height: 500rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		background-color: #fff;

		.itembox {
			width: 100%;
			min-height: 371rpx;
			padding: 26rpx 0;
			box-sizing: border-box;
			border-bottom: 1rpx solid #F5F5F5;

			.topbox {
				width: 100%;
				height: 72rpx;
				display: flex;
				align-items: center;

				.r-box {
					width: 600rpx;
					height: 72rpx;
					margin-left: 8rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.nametxt {
						width: 100%;
						height: 38rpx;
						font-weight: 500;
						font-size: 26rpx;
						color: #222222;
						text-align: left;
						display: flex;
					}

					.timetxt {
						width: 100%;
						height: 34rpx;
						font-weight: 300;
						font-size: 22rpx;
						color: #AFAFAF;
						text-align: left;
					}
				}
			}

			.centerbox {
				width: 100%;
				min-height: 220rpx;
				margin-top: 26rpx;
				box-sizing: border-box;

				.dongtaitxt {
					width: 100%;
					min-height: 38rpx;
					font-weight: 400;
					font-size: 26rpx;
					color: #000000;
					text-align: left;
					margin-bottom: 24rpx;
				}

				.imgbox {
					width: 100%;
					min-height: 220rpx;
					display: flex;
					flex-wrap: wrap;
				}
			}

			.fpzbox {
				width: 100%;
				height: 92rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 100rpx;
				box-sizing: border-box;

				.fenxiang {
					width: 100rpx;
					height: 92rpx;
					display: flex;
					align-items: center;

					.nums {
						width: 100%;
						height: 36rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #666666;
						text-align: left;
						margin-left: 6rpx;
					}
				}

				.pinglun {
					width: 100rpx;
					height: 92rpx;
					display: flex;
					align-items: center;

					.nums {
						width: 100%;
						height: 36rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #666666;
						text-align: left;
						margin-left: 6rpx;
					}
				}

				.zan {
					width: 100rpx;
					height: 92rpx;
					display: flex;
					align-items: center;

					.nums {
						width: 100%;
						height: 36rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #666666;
						text-align: left;
						margin-left: 6rpx;
					}
				}
			}
		}
	}

	.popbox {
		width: 750rpx;
		height: 520rpx;
		background: #FFFFFF;
		border-radius: 40rpx 40rpx 0rpx 0rpx;
		padding: 0 30rpx;
		box-sizing: border-box;

		.zhiding {
			width: 690rpx;
			height: 124rpx;
			border-bottom: 2rpx solid #F5F5F5;
			text-align: center;
			line-height: 124rpx;
			font-weight: 400;
			font-size: 30rpx;
			color: #000000;
			text-align: center;
		}

		.yinc {
			width: 690rpx;
			height: 124rpx;
			border-bottom: 2rpx solid #F5F5F5;
			text-align: center;
			line-height: 124rpx;
			font-weight: 400;
			font-size: 30rpx;
			color: #000000;
			text-align: center;
		}

		.sanc {
			width: 690rpx;
			height: 124rpx;
			border-bottom: 2rpx solid #F5F5F5;
			text-align: center;
			line-height: 124rpx;
			font-weight: 400;
			font-size: 30rpx;
			color: #000000;
			text-align: center;
		}

		.quxiao {
			width: 690rpx;
			height: 124rpx;
			text-align: center;
			line-height: 124rpx;
			font-weight: 400;
			font-size: 30rpx;
			color: #AFAFAF;
			text-align: center;
		}
	}
</style>